#include<bits/stdc++.h>
using namespace std;
using ll = long long;
//Vishal Kumar Singh
//AVS
int main(){
ll n,sum=0;
cin>>n;
ll a[n];
for (int i = 0; i < n; i++)
{
cin>>a[i];
}
for (int i = 1; i < n; i++)
{
if (a[i-1]>a[i])
{
sum+=(a[i-1]-a[i]);
}
}
cout<<sum;
}
465A - inc ARG | 1260A - Heating |
1740D - Knowledge Cards | 1028A - Find Square |
1370B - GCD Compression | 888D - Almost Identity Permutations |
1106C - Lunar New Year and Number Division | 849B - Tell Your World |
1650E - Rescheduling the Exam | 899C - Dividing the numbers |
1023C - Bracket Subsequence | 1579D - Productive Meeting |
1749E - Cactus Wall | 1682C - LIS or Reverse LIS |
578A - A Problem about Polyline | 1038E - Maximum Matching |
1141C - Polycarp Restores Permutation | 1685A - Circular Local MiniMax |
432B - Football Kit | 10C - Digital Root |
743B - Chloe and the sequence | 909D - Colorful Points |
1283C - Friends and Gifts | 605B - Lazy Student |
1687B - Railway System | 61D - Eternal Victory |
588B - Duff in Love | 12C - Fruits |
447B - DZY Loves Strings | 325A - Square and Rectangles |